#include "mainwindow.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QTextEdit>

#include "qxmaterial/matappbar.h"
#include "qxmaterial/matcheckbox.h"
#include "qxmaterial/matradiobutton.h"
#include "qxmaterial/matautocomplete.h"
#include "qxmaterial/mattextfield.h"
#include "qxmaterial/matscrollbar.h"
#include "qxmaterial/matavatar.h"
#include "qxmaterial/matbadge.h"
#include "qxmaterial/matslider.h"
#include "qxmaterial/matprogress.h"
#include "qxmaterial/matflatbutton.h"
#include "qxmaterial/matraisedbutton.h"
#include "qxmaterial/matfab.h"
#include "qxmaterial/matcircularprogress.h"
#include "qxmaterial/mattheme.h"
#include "qxmaterial/maticonbutton.h"
#include "qxmaterial/mattoggle.h"
#include "qxmaterial/mattabbar.h"

QX_MATERIAL_USE_NAMESPACE

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QWidget *cw = new QWidget(this);
    setCentralWidget(cw);

    QVBoxLayout *mainLayout = new QVBoxLayout(cw);

    // appbar
    MatAppBar *appBar = new MatAppBar();
    const QColor &foregroundColor = appBar->foregroundColor();

    QLabel *label = new QLabel("Inbox");
    label->setAttribute(Qt::WA_TranslucentBackground);
    label->setForegroundRole(QPalette::WindowText);
    label->setContentsMargins(6, 0, 0, 0);

    QPalette palette = label->palette();
    palette.setColor(label->foregroundRole(), foregroundColor);
    label->setPalette(palette);

    label->setFont(QFont("Roboto", 18, QFont::Normal));

    MatIconButton *button = new MatIconButton(MatTheme::icon("navigation", "menu"));
    button->setIconSize(QSize(24, 24));
    button->setColor(foregroundColor);
    button->setFixedWidth(42);

    QHBoxLayout *appBarLayout = appBar->appBarLayout();
    appBarLayout->addWidget(button);
    appBarLayout->addWidget(label);
    appBarLayout->addStretch(1);

    mainLayout->addWidget(appBar);

    // new mid
    QHBoxLayout *midHLayout = new QHBoxLayout();
    midHLayout->setSpacing(5);
    midHLayout->setContentsMargins(0, 0, 0, 0);

    // HBoxLayout, VBoxLayout
    QHBoxLayout *hLayout = nullptr;
    QVBoxLayout *vLayout = nullptr;

    // checkbox
    MatCheckBox *cb1 = new MatCheckBox();
    cb1->setText("Option 1");
    MatCheckBox *cb2 = new MatCheckBox();
    cb2->setText("Option 2");
    MatToggle *toggle = new MatToggle();
    vLayout = new QVBoxLayout();
    vLayout->setSpacing(0);
    vLayout->setContentsMargins(0, 0, 0, 0);
    vLayout->addWidget(cb1);
    vLayout->addWidget(cb2);
    vLayout->addWidget(toggle);
    midHLayout->addLayout(vLayout);

    // radiobutton
    MatRadioButton *rb1 = new MatRadioButton();
    rb1->setText("Option 1");
    MatRadioButton *rb2 = new MatRadioButton();
    rb2->setText("Option 2");
    MatRadioButton *rb3 = new MatRadioButton();
    rb3->setText("Option 3");
    vLayout = new QVBoxLayout();
    vLayout->setSpacing(0);
    vLayout->setContentsMargins(0, 0, 0, 0);
    vLayout->addWidget(rb1);
    vLayout->addWidget(rb2);
    vLayout->addWidget(rb3);
    midHLayout->addLayout(vLayout);

    vLayout = new QVBoxLayout();
    vLayout->setSpacing(10);
    vLayout->setContentsMargins(0, 0, 0, 0);

    hLayout = new QHBoxLayout();
    hLayout->setSpacing(10);
    hLayout->setContentsMargins(0, 10, 0, 10);
    hLayout->addStretch();
    MatIconButton *iconButton = nullptr;
    iconButton = new MatIconButton(MatTheme::icon("toggle", "star"));
    hLayout->addWidget(iconButton);
    iconButton = new MatIconButton(MatTheme::icon("communication", "call"));
    hLayout->addWidget(iconButton);
    iconButton = new MatIconButton(MatTheme::icon("action", "alarm"));
    hLayout->addWidget(iconButton);
    iconButton = new MatIconButton(MatTheme::icon("action", "tab"));
    hLayout->addWidget(iconButton);
    hLayout->addStretch();
    vLayout->addLayout(hLayout);

    MatFlatButton *fb = new MatFlatButton(tr("I'M FLAT"));
    vLayout->addWidget(fb);
    MatRaisedButton *raisedBtn = new MatRaisedButton(tr("RISE UP"));
    vLayout->addWidget(raisedBtn);

    midHLayout->addLayout(vLayout);

    // autocomplete
    QStringList states =
      { "Alabama"
      , "Alaska"
      , "American Samoa"
      , "Arizona"
      , "Arkansas"
      , "California"
      , "Colorado"
      , "Connecticut"
      , "Delaware"
      , "District of Columbia"
      , "Florida"
      , "Georgia"
      , "Guam"
      , "Hawaii"
      , "Idaho"
      , "Illinois"
      , "Indiana"
      , "Iowa"
      , "Kansas"
      , "Kentucky"
      , "Louisiana"
      , "Maine"
      , "Maryland"
      , "Massachusetts"
      , "Michigan"
      , "Minnesota"
      , "Mississippi"
      , "Missouri"
      , "Montana"
      , "Nebraska"
      , "Nevada"
      , "New Hampshire"
      , "New Jersey"
      , "New Mexico"
      , "New York"
      , "North Carolina"
      , "North Dakota"
      , "Northern Marianas Islands"
      , "Ohio"
      , "Oklahoma"
      , "Oregon"
      , "Pennsylvania"
      , "Puerto Rico"
      , "Rhode Island"
      , "South Carolina"
      , "South Dakota"
      , "Tennessee"
      , "Texas"
      , "Utah"
      , "Vermont"
      , "Virginia"
      , "Virgin Islands"
      , "Washington"
      , "West Virginia"
      , "Wisconsin"
      , "Wyoming"
    };
    MatAutoComplete *autocomplete = new MatAutoComplete();
    autocomplete->setDataSource(states);
    // textfield
    MatTextField *textField = new MatTextField();
    textField->setLabel("Wat is this");
    MatSlider *slider = new MatSlider();
    MatProgress *progress = new MatProgress();
    vLayout = new QVBoxLayout();
    vLayout->setSpacing(5);
    vLayout->setContentsMargins(0, 0, 0, 0);
    vLayout->addWidget(slider);
    vLayout->addWidget(progress);
    vLayout->addWidget(textField);
    vLayout->addWidget(autocomplete);
    midHLayout->addLayout(vLayout);

    QTextEdit *edit = new QTextEdit;
    edit->setText("<p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p>");
    edit->setLineWrapMode(QTextEdit::NoWrap);
    edit->update();
    edit->setMaximumHeight(150);
    MatScrollBar *verticalScrollbar = new MatScrollBar();
    MatScrollBar *horizontalScrollbar = new MatScrollBar();
    edit->setVerticalScrollBar(verticalScrollbar);
    edit->setHorizontalScrollBar(horizontalScrollbar);
    horizontalScrollbar->setOrientation(Qt::Horizontal);
    vLayout = new QVBoxLayout();
    vLayout->setSpacing(0);
    vLayout->setContentsMargins(0, 0, 0, 0);
    vLayout->addWidget(edit);
    midHLayout->addLayout(vLayout);

    midHLayout->addStretch();

    mainLayout->addLayout(midHLayout);

    // new mid
    midHLayout = new QHBoxLayout();
    midHLayout->setSpacing(5);
    midHLayout->setContentsMargins(0, 0, 0, 0);

    hLayout = new QHBoxLayout();
    hLayout->setSpacing(10);
    hLayout->setContentsMargins(0, 10, 0, 10);
    MatAvatar *avatar = new MatAvatar(QChar('X'));
    hLayout->addWidget(avatar);
    avatar = new MatAvatar(MatTheme::icon("communication", "message"));
    avatar->setSize(60);
    MatBadge *badge = new MatBadge();
    badge->setParent(avatar);
    badge->setRelativePosition(15, 15);
    badge->setText("3");
    hLayout->addWidget(avatar);
    MatCircularProgress *circularProgress = new MatCircularProgress();
    hLayout->addWidget(circularProgress);
    MatTabBar *tabBar = new MatTabBar();
    tabBar->addTab("Media");
    tabBar->addTab("Playback");
    tabBar->addTab("Audio");
    tabBar->addTab("Video");
    tabBar->addTab("Tools");
    tabBar->setMinimumWidth(400);
    hLayout->addWidget(tabBar);
    MatFloatingActionButton *fab = new MatFloatingActionButton(MatTheme::icon("content", "add"));
    hLayout->addWidget(fab);
    hLayout->addStretch();
    midHLayout->addLayout(hLayout);

    midHLayout->addStretch(1);

    mainLayout->addLayout(midHLayout);

    mainLayout->addStretch(1);

    setWindowTitle(tr("Material Demo"));
    resize(800, 400);
}

MainWindow::~MainWindow()
{
}

